//
//  WSJTipTool.m
//  NursingAssociation
//
//  Created by wsj2015 on 2017/3/16.
//  Copyright © 2017年 wsj2015. All rights reserved.
//

#import "WSJTipTool.h"
#import "AMPopTip.h"
@implementation WSJTipTool



+ (BOOL)hasGuideForAcount:(NSString *)accout function:(NSString *)funKey{
    
    return [[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"%@_%@",accout,funKey]];

}


+ (void)noteGuidedForAcount:(NSString *)accout function:(NSString*)funKey{
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:[NSString stringWithFormat:@"%@_%@",accout,funKey]];
    [[NSUserDefaults standardUserDefaults] synchronize];

}



+ (void)showTipForFunction:(NSString *)funKey withWords:(NSString *)words
                                              withView:(UIView *)view
                                              fromFrame:(CGRect)frame
                                              direction:(AMPopTipDirection)direction

{
    
    if ([self hasGuideForAcount:[HELAppManager userInfo].account function:funKey]) {
        return;
    }
    
    AMPopTip  *popTip = [AMPopTip popTip];
    popTip.tag = 3000;
    popTip.font = [UIFont fontWithName:@"Avenir-Medium" size:12];
 
    popTip.edgeMargin = 5;
    popTip.offset = 2;
    popTip.popoverColor = kPinchColor;
    popTip.edgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
    popTip.shouldDismissOnTap = YES;
//    popTip.shouldDismissOnTapOutside = YES;
    popTip.actionAnimation = AMPopTipActionAnimationFloat;
     NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:words attributes:@{NSFontAttributeName: [UIFont fontWithName:@"Avenir-Medium" size:12], NSForegroundColorAttributeName: [UIColor whiteColor]}];
    [popTip showAttributedText:attributedText direction:direction maxWidth:200 inView:view fromFrame:frame];
    [popTip startActionAnimation];
    weakSelf_define;
    popTip.dismissHandler = ^(){
        [weakSelf noteGuidedForAcount:[HELAppManager userInfo].account function:funKey];
    };
    __weak AMPopTip *weakTip = popTip;
    popTip.tapHandler = ^(){
        [weakTip stopActionAnimation];
        [weakTip hide];
    };
 
}

+ (void)hideWithPopWithSupview:(UIView *)supView
{
    AMPopTip *tip = [supView viewWithTag:3000];
   
    if (tip) {
         tip.dismissHandler();
        [tip stopActionAnimation];
        [tip hide];
        dispatch_after(.5, dispatch_get_main_queue(), ^{
            [tip removeFromSuperview];
        });
    }
   
}




@end
